package blyth;

import java.awt.Point;

public abstract class Task {

    public World world;
    public int priority;
    public Point goal;
    public Agent assignedTo;
    public int attacked; // Times the agent was attacked during this task
    //public int blocked; // Times the agent wasn't able to find route to goal

    public Task(World world, int priority, Point goal) {
        this.world = world;
        this.priority = priority;
        this.goal = goal;
        this.assignedTo = null;
        this.attacked = 0;
        //this.blocked = 0;
    }
    
    public int Distance() {
        return Heur.Manhattan(assignedTo.position, goal);
    }
    
    public int Distance(Agent agent) {
        return Heur.Manhattan(agent.position, goal);
    }
    
    public int Distance(Point pos) {
        return Heur.Manhattan(pos, goal);
    }
    
    public boolean WontMakeItToGoal(Agent agent) {
        return agent.energy < Distance(agent) * Tile.basicMovementCost
                || (agent.inWater && (double) agent.energy < (double) Tile.basicMovementCost
                * Tile.waterCostMultiplier);
    }
    
    // Checks if this task is valid, if it's not it should be removed
    public abstract boolean IsValid();
    
    // Checks for how fit agent is for this task
    public abstract int AvailabilityFrom(Agent agent);
    
    // Solves this task, returning a command to pass
    public abstract Command Solve();    
}
